package com.serviceImpl;

import com.dao.ResourceDao;
import com.domain.Resources;
import com.server.ResourceService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service("resourceService")
public class ResourceServiceImpl implements ResourceService{

    @Resource(name="resourceDao")
    private ResourceDao resourceDao;

    //根据创建时间查询
    public List<Resources> descCreateDate(Integer space_id) {
        return resourceDao.descCreateDate(space_id);
    }

    public List<Resources> selectResourceByMemberId(Integer member_id) { return resourceDao.selectResourceByMemberId(member_id); }

    //根据标题名模糊查询资源
    public List<Resources> selectResourceByTitle(String title) { return resourceDao.selectResourceByTitle(title); }

    public Resources selectResourceByTitleAndMemberId(String title, Integer member_id) {
        return resourceDao.selectResourceByTitleAndMemberId(title,member_id);
    }

    //根据space_id返回数值
    public int findResourceTotal(Integer space_id) {
        return resourceDao.findResourceTotal(space_id);
    }

    //显示所有资源信息
    public  List<Resources> showResource(Integer space_id){
        return resourceDao.showResource(space_id);
    }

    //分页查询
     public List<Resources> findAllByPage(int space_id,int page,int pageSize){
        int from=(page-1)*pageSize;
        return resourceDao.findAllByPage(space_id,from,pageSize);
    }

    //根据资源id显示资源信息
    public Resources showResourceById(Integer id){
        return resourceDao.showResourceById(id);
    }

    //根据资源id和空间id显示资源信息
    public Resources showResourceByIdAndSpaceId(Integer id,Integer space_id){
        return resourceDao.showResourceByIdAndSpaceId(id,space_id);
    }

    //根据id删除资源
    public Integer deleteByResourceId(Integer id){
        return resourceDao.deleteByResourceId(id);
    }

    //根据资源名，作者，标签进行模糊查询
    public List BlurredSelect(Integer space_id,String title,String author,String label){
        return resourceDao.BlurredSelect(space_id,title,author,label);
    }

    //根据资源id进行修改
    public Integer updateResource(Integer id,String title,String content,String detail,String label,Date updatetime){
        return resourceDao.updateResource(id,title,content,detail,label,updatetime);
    }

    //添加资源
    public Integer insertResource(String title,String content,String author,String detail,String label,Date createdate,Date updatetime,Integer member_id,Integer space_id){
        return resourceDao.insertResource(title,content,author,detail,label,createdate,updatetime,member_id,space_id);
    }

    //查询最后一条语句
    public Resources findLastId(){
        return resourceDao.findLastId();
    }

    @Override
    public int deleteResourceBySpaceId(int space_id) {
        return resourceDao.deleteResourceBySpaceId(space_id);
    }

}
